#ifndef UI_H
#define UI_H

#ifdef __cplusplus
extern "C" {
#endif
#include <Arduino.h>
#include <lvgl.h>
#include "my_indev.h"



static void slider_event_cb(lv_event_t * e)
{

    //lv_event_code_t code = lv_event_get_code(e);//获取事件代码,LV_EVENT_PRESSED,LV_EVENT_CLICKED,LV_EVENT_LONG_PRESSED(lvgl库自带，外部驱动只返回有LV_EVENT_PRESSED即可)
    Serial.println("调用");
    lv_obj_t * slider = lv_event_get_target_obj(e);
    /*Create a label above the slider*/


    static lv_obj_t * label = lv_label_create(lv_screen_active());
    lv_obj_align_to(label, slider, LV_ALIGN_OUT_TOP_MID, 0, -15);    /*Align top of the slider*///设置标签在slider上方其中间
    /*Refresh the text*/
    lv_label_set_text_fmt(label, "%"LV_PRId32, lv_slider_get_value(slider));
   

}

/**
 * Create a button with a label and react on click event.
 */
void lv_example_get_started_2(void)
{
   
 //创建旋转编码器为输入设备
  /*Register at least one display before you register any input devices*/
  static lv_indev_t * indev = lv_indev_create();
  lv_indev_set_type(indev, LV_INDEV_TYPE_ENCODER);   /*See below.*/
  lv_indev_set_read_cb(indev, encoder_read);  /*See below.*/  //绑定输入设备的回调函数

   //  UI设计
  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /*Create a slider in the center of the display*/
    lv_obj_t * slider = lv_slider_create(lv_screen_active());
    lv_obj_set_width(slider, 200);                          /*Set the width*/
    lv_obj_center(slider);                                  /*Align to the center of the parent (screen)*/
    lv_obj_add_event_cb(slider, slider_event_cb, LV_EVENT_VALUE_CHANGED, NULL);     /*Assign an event function*/

  
  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  /* 创建group 后面将控件绑定到组即绑定到输入设备 */
  lv_group_t * group = lv_group_create();
  lv_indev_set_group(indev, group);


  lv_group_add_obj(group,slider);


}












#ifdef __cplusplus
} /*extern "C"*/
#endif

#endif /*UI_H*/